//获取当前需要的资源
function getSubRes(devHandle, resourceType) {
    var operator = NPCCIF.COMMON_GetChildren(NPCCILY.Plug.ccPlugin, devHandle);
    if (operator.errorCode == ErrorCode.NP_E_OK && operator.value) {
        if (operator.value.constructor != Array) {
            operator.value = [operator.value];
        }

        var getHandle = null;
        $.each(operator.value, function(resIdx, resHandle) {
            var resType = NPCCIF.COMMON_GetResType(NPCCILY.Plug.ccPlugin, resHandle).value;
            if (Number(resType) == resourceType) {
                getHandle = resHandle;
                return false;
            }
        })

        return getHandle;
    }
}

// 资源树加载时获取每个设备对应的所有摄像头句柄
function getSubResCameraHandle(devHandle, resourceType) {
    var operator = NPCCIF.COMMON_GetChildren(NPCCILY.Plug.ccPlugin, devHandle);
    if (operator.errorCode == ErrorCode.NP_E_OK && operator.value) {
        if (operator.value.constructor != Array) {
            operator.value = [operator.value];
        }

        var getHandle = [];
        $.each(operator.value, function(resIdx, resHandle) {
            var resType = NPCCIF.COMMON_GetResType(NPCCILY.Plug.ccPlugin, resHandle).value;
            if (Number(resType) == resourceType) {
                getHandle.push(resHandle);
            }
        })

        return getHandle;
    }
}

// 获取兄弟资源
function getSiblingRes(cameraHandle, resourceType) {
    var devHandle = NPCCIF.COMMON_GetParent(NPCCILY.Plug.ccPlugin, cameraHandle).value;
    var operator = NPCCIF.COMMON_GetChildren(NPCCILY.Plug.ccPlugin, devHandle);
    if (operator.errorCode == ErrorCode.NP_E_OK && operator.value) {
        if (operator.value.constructor != Array) {
            operator.value = [operator.value];
        }

        var getHandle = null;
        $.each(operator.value, function(resIdx, resHandle) {
            var resType = NPCCIF.COMMON_GetResType(NPCCILY.Plug.ccPlugin, resHandle).value;
            if (Number(resType) == resourceType) {
                getHandle = resHandle;
                return false;
            }
        })

        return getHandle;
    }
}

// 获取当前在线设备句柄
function onlineDevice() {
    var onlines = [];
    //获取所有设备句柄
    var operator = NPCCIF.RSTW_GetPUList(NPCCILY.Plug.ccPlugin, WebClient.hServer);
    if (operator.errorCode == ErrorCode.NP_E_OK) {
        var hPuArray = operator.value;
        // 进行在线排序
        $.each(hPuArray, function(index, devHandle) {
            var bOnline = NPCCIF.COMMON_IsOnline(NPCCILY.Plug.ccPlugin, devHandle).value;
            var bEnable = NPCCIF.COMMON_IsEnable(NPCCILY.Plug.ccPlugin, devHandle).value;
            if (bOnline == 1 && bEnable == 1) {
                onlines.push(devHandle);
            }
        });
    }

    return onlines;
}
